<template>
  <div class="base-echart">
    <div ref="echartDivRef" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script lang="ts" setup>
// 使用setup最新版
import { ref, onMounted, defineProps, watchEffect } from 'vue'
import useEchart from '../hooks/useEcharts'

const props = defineProps({
  width: {
    type: String,
    default: '100%',
  },
  height: {
    type: String,
    default: '360px',
  },
  option: {
    type: Object,
    default: () => {},
  },
})

const echartDivRef = ref<HTMLElement>()

onMounted(() => {
  const { setOption } = useEchart(echartDivRef.value!)
  watchEffect(() => {
    setOption(props.option)
  })
  // const echartInstance = echarts.init(echartDivRef.value!)
  // echartInstance.setOption(props.option)
})
</script>

<style lang="less" scoped></style>
